<template>
    <div class="icons">
        <swiper :options="swiperOption">
            <!-- slides -->
            <swiper-slide v-for="(page, index) in pages" :key="index">
                <div class="icon" v-for="item in page" :key="item.id">
                    <img class="icon-img" :src="item.imgUrl" :alt="item.tilte">
                    <p class="icon-desc">{{ item.title }}</p>
                </div>
            </swiper-slide>
            <!-- Optional controls -->
            <div class="swiper-pagination"  slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      var pages = []
      this.list.forEach((item, index) => {
        var page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
    @import '~styles/variables.styl'
    @import '~styles/mixins.styl'
    .icons >>> .swiper-container
        overflow hidden
        height 0
        width 100%
        padding-bottom 50%
        .icon
            overflow hidden
            float left
            width 25%
            height 0
            padding-bottom 25%
            text-align center
            .icon-img
                width 1.1rem
                margin .1rem
            .icon-desc
                height .44rem
                line-height .44rem
                color $textColor
                ellipsis()
</style>
